﻿using System;
using System.Linq.Expressions;

namespace Tequila.Phone.Infrastructure
{
    internal static class Extensions
    {
        public static string GetMemberName<T>(this Expression<Func<T>> expression)
        {
            var lambda = (LambdaExpression)expression;

            var memberExpression = lambda.Body is UnaryExpression
                                       ? (MemberExpression)((UnaryExpression)lambda.Body).Operand
                                       : (MemberExpression)lambda.Body;

            return memberExpression.Member.Name;
        }
    }
}
